package jianzhi

func reverseList(head *ListNode) *ListNode {
	var newHead *ListNode
	cur := head
	for cur != nil {
		next := cur.Next
		cur.Next = newHead
		newHead = cur
		cur = next
	}
	return newHead
}

func reverseList2(head *ListNode) *ListNode {

	if head == nil {
		return head
	}

	nodeList := []*ListNode{}
	for temp := head; temp != nil; temp = temp.Next {
		nodeList = append(nodeList, temp)
	}

	for i := len(nodeList) - 1; i >= 0; i-- {
		if i == 0 {
			nodeList[i].Next = nil
		} else {
			nodeList[i].Next = nodeList[i-1]
		}
	}

	return nodeList[len(nodeList)-1]

}
